home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Mud 4.0 / simul_efun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  2.7 KB  |  115 lines  |  [TEXT/MPS ]

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "lint.h"
  5. #include "interpret.h"
  6. #include "object.h"
  7. #include "exec.h"
  8. #include "config.h"
  9. #include "rc.h"
  10.  
  11. #ifdef mac
  12. #include "mac.h"
  13. #endif
  14.  
  15. static struct function *simul_efunp = 0;
  16. static int num_simul_efun;
  17.  
  18. /* Don't release this pointer ever. It is used elsewhere. */
  19. static char *simul_efun_file_name;
  20.  
  21. extern void start_new_file PROT((FILE *, int));
  22. extern void end_new_file PROT((void));
  23. extern int give_uid_to_object PROT((struct object *));
  24.  
  25. /*
  26.  * If there is a simul_efun file, then take care of it and extract all
  27.  * information we need.
  28.  */
  29. void get_simul_efun(svp)
  30.     struct svalue *svp;
  31. {
  32.     struct object *ob;
  33.     struct function *funp;
  34.     int i;
  35.  
  36.     FILE *f;
  37.     extern struct program *prog;
  38.     extern char *current_file;
  39.     extern int total_lines;
  40.     extern int num_parse_error;
  41.     extern char *inherit_file;
  42.     char tmpname[128];
  43.  
  44.     simul_efun_file_name = make_shared_string(SIMUL_EFUN);
  45.  
  46.     strcpy(tmpname, SIMUL_EFUN);
  47.     strcat(tmpname, ".c");
  48.     f = fopen(tmpname, "r");
  49.     if (f == 0) {
  50.         fprintf(stderr, "%s not found.\n", tmpname);
  51.         LPExit(1);
  52.     }
  53.     start_new_file(f,0);
  54.     current_file = string_copy(tmpname);    /* This one is freed below */
  55.     compile_file();
  56.     end_new_file();
  57.     total_lines = 0;
  58.     (void)fclose(f);
  59.     xfree(current_file);
  60.     current_file = 0;
  61.  
  62.     if (inherit_file || num_parse_error > 0 || prog == 0) {
  63.         fprintf(stderr, "Error in %s.\n", tmpname);
  64.         LPExit(1);
  65.     }
  66.  
  67.     num_simul_efun = prog->num_functions;
  68.     fprintf(stderr,"%s loaded: %d functions\n", SIMUL_EFUN,
  69.         prog->num_functions);
  70.     if (num_simul_efun == 0)
  71.     return;
  72.     funp = prog->functions;
  73.     simul_efunp = (struct function *)
  74.     xalloc(sizeof (struct function) * num_simul_efun);
  75.     for (i=0; i < prog->num_functions; i++) {
  76.     simul_efunp[i].name = make_shared_string(funp[i].name);
  77.     simul_efunp[i].flags = funp[i].flags;
  78.     simul_efunp[i].num_arg = funp[i].num_arg;
  79.     simul_efunp[i].type = funp[i].type & TYPE_MOD_MASK;
  80.     }
  81.  
  82.     ob = get_empty_object(prog->num_variables);
  83.  
  84.     ob->name = string_copy(SIMUL_EFUN);
  85.     ob->prog = prog;
  86.     ob->next_all = obj_list;
  87.     obj_list = ob;
  88.     enter_object_hash(ob);    /* add name to fast object lookup table */
  89.     current_object = 0;
  90.     give_uid_to_object(ob);
  91. }
  92.  
  93. /*
  94.  * Test if 'name' is a simul_efun. The string pointer MUST be a pointer to
  95.  * a shared string.
  96.  */
  97. struct function *find_simul_efun(name)
  98.     char *name;
  99. {
  100.     int i;
  101.     for (i=0; i < num_simul_efun; i++) {
  102.     if (name == simul_efunp[i].name)
  103.         return &simul_efunp[i];
  104.     }
  105.     return 0;
  106. }
  107.  
  108. char *query_simul_efun_file_name() {
  109. #ifdef DEBUG
  110.     if (simul_efunp == 0)
  111.     fatal("query_simlu_efun_file_name called when non exists!\n");
  112. #endif
  113.     return simul_efun_file_name;
  114. }
  115.